﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DBService;
using YArchitech.Controls;
using YArchitech.Revit.MEP.Opening.Properties;

namespace YArchitech.Revit.MEP.Opening
{
	public partial class DlgEdit : System.Windows.Forms.Form
	{
		public DlgEdit(DbOpeningBase opening)
		{
			this.dob = opening;
			this.InitializeComponent();
		}

		private void DlgEdit_Load(object sender, EventArgs e)
		{
			this.txtCutType.Text = this.dob.CutTypeString;
			this.txtHostType.Text = this.dob.HostTypeString;
			this.txtLevel.Text = this.dob.LevelString;
			this.txtStatus.Text = this.dob.OpeningStatusString;
			this.txtOpeningSize.Text = this.dob.SectionParameterString;
			this.txtRemark.Text = this.dob.Remark;
			if (this.dob.SectionParameter.SectionType == DBService.SectionType.Arc)
			{
				this.isRect = false;
				this.pbxCircle.Visible = true;
				this.lblR.Visible = true;
				this.txtR.Visible = true;
				this.txtR.Text = this.dob.BoxParameter.Parameter1.ToString();
				return;
			}
			this.isRect = true;
			this.pbxRect.Visible = true;
			this.lblTop.Visible = true;
			this.txtTop.Visible = true;
			this.txtTop.Text = this.dob.BoxParameter.Parameter1.ToString();
			this.lblDown.Visible = true;
			this.txtDown.Visible = true;
			this.txtDown.Text = this.dob.BoxParameter.Parameter2.ToString();
			this.lblLeft.Visible = true;
			this.txtLeft.Visible = true;
			this.txtLeft.Text = this.dob.BoxParameter.Parameter3.ToString();
			this.lblRight.Visible = true;
			this.txtRight.Visible = true;
			this.txtRight.Text = this.dob.BoxParameter.Parameter4.ToString();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			try
			{
				this.dob.Remark = this.txtRemark.Text;
				if (this.isRect)
				{
					this.dob.BoxParameter.Parameter1 = Convert.ToDouble(this.txtTop.Text);
					this.dob.BoxParameter.Parameter2 = Convert.ToDouble(this.txtDown.Text);
					this.dob.BoxParameter.Parameter3 = Convert.ToDouble(this.txtLeft.Text);
					this.dob.BoxParameter.Parameter4 = Convert.ToDouble(this.txtRight.Text);
				}
				else
				{
					this.dob.BoxParameter.Parameter1 = Convert.ToDouble(this.txtR.Text);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private DbOpeningBase dob;

		private bool isRect;
	}
}
